package com.ktgj.flight.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ktgj.common.log.annotation.Log;
import com.ktgj.common.log.enums.BusinessType;
import com.ktgj.common.security.annotation.PreAuthorize;
import com.ktgj.flight.domain.Homebanner;
import com.ktgj.flight.service.IHomebannerService;
import com.ktgj.common.core.web.controller.BaseController;
import com.ktgj.common.core.web.domain.AjaxResult;
import com.ktgj.common.core.utils.poi.ExcelUtil;
import com.ktgj.common.core.web.page.TableDataInfo;

/**
 * 首页动态标题Controller
 * 
 * @author ruoyi
 * @date 2021-10-26
 */
@ControllerAdvice
@RestController
@RequestMapping("/homebanner")
public class HomebannerController extends BaseController
{
    @Autowired
    private IHomebannerService homebannerService;

    /**
     * 查询首页动态标题列表
     */
    @PreAuthorize(hasPermi = "flight:homebanner:list")
    @GetMapping("/list")
    public TableDataInfo list(Homebanner homebanner)
    {
        startPage();
        List<Homebanner> list = homebannerService.selectHomebannerList(homebanner);
        return getDataTable(list);
    }

    /**
     * 导出首页动态标题列表
     */
    @PreAuthorize(hasPermi = "flight:homebanner:export")
    @Log(title = "首页动态标题", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Homebanner homebanner) throws IOException
    {
        List<Homebanner> list = homebannerService.selectHomebannerList(homebanner);
        ExcelUtil<Homebanner> util = new ExcelUtil<Homebanner>(Homebanner.class);
        util.exportExcel(response, list, "首页动态标题数据");
    }

    /**
     * 获取首页动态标题详细信息
     */
    @PreAuthorize(hasPermi = "flight:homebanner:query")
    @GetMapping(value = "/{bannerId}")
    public AjaxResult getInfo(@PathVariable("bannerId") Long bannerId)
    {
        return AjaxResult.success(homebannerService.selectHomebannerById(bannerId));
    }

    /**
     * 新增首页动态标题
     */
    @PreAuthorize(hasPermi = "flight:homebanner:add")
    @Log(title = "首页动态标题", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Homebanner homebanner)
    {
        return toAjax(homebannerService.insertHomebanner(homebanner));
    }

    /**
     * 修改首页动态标题
     */
    @PreAuthorize(hasPermi = "flight:homebanner:edit")
    @Log(title = "首页动态标题", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Homebanner homebanner)
    {
        return toAjax(homebannerService.updateHomebanner(homebanner));
    }

    /**
     * 删除首页动态标题
     */
    @PreAuthorize(hasPermi = "flight:homebanner:remove")
    @Log(title = "首页动态标题", businessType = BusinessType.DELETE)
	@DeleteMapping("/{bannerIds}")
    public AjaxResult remove(@PathVariable Long[] bannerIds)
    {
        return toAjax(homebannerService.deleteHomebannerByIds(bannerIds));
    }
}
